/*
 * MLE
 * DP
 **/
#include <stdio.h>

int ugly[200000000];
int np[1500];
int main(int argc, char **argv)
{
	int i = 2, counter = 0;
	int n;

	ugly[1] = 1;
	while (counter < 1500) {
		if (!(i % 2)) {
			if (ugly[i / 2] == 0)
				ugly[i] = 0;
			else {
				np[counter] = i;
				counter++;
				ugly[i] = 1;
			}
		}
		else if (!(i % 3)) {
			if (ugly[i / 3] == 0)
				ugly[i] = 0;
			else {
				np[counter] = i;
				counter++;
				ugly[i] = 1;
			}
		}
		else if (!(i % 5)) {
			if (ugly[i / 5] == 0)
				ugly[i] = 0;
			else {
				np[counter] = i;
				counter++;
				ugly[i] = 1;
			}
		}
		else ugly[i] = 0;
		i++;
	}
	while (scanf("%d", &n) != EOF && n != 0) {
		printf("%d\n", ugly[np[n - 1]]);
	}
	return 0;
}
